﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessPlatform.Core.BusinessObject.BOParser;
using BusinessPlatform.Core.BusinesObjectType;

namespace BusinessPlatform.Core.BusinessObject
{
    /// <summary>
    /// 集合对象
    /// </summary>
    /// <typeparam name="ParentType">父对象</typeparam>
    /// <typeparam name="ChildType">子对象</typeparam>
    public abstract class BusinessObjectListBase<ParentType, ChildType> : List<ChildType>, IBusinessObjectListBaseT<ChildType>
        where ParentType : IBusinessObjectBase
        where ChildType : IBusinessObjectBase
    {
        /// <summary>
        /// 基类
        /// </summary>
        private ParentType _parent;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="parent"></param>
        protected BusinessObjectListBase(ParentType parent)
        {
            _parent = parent;
        }
        /// <summary>
        /// 获取基类
        /// </summary>
        public ParentType Parent
        {
            get { return _parent; }
        }
        public void SetParent(ParentType parent)
        {
            _parent = parent;
        }
        /// <summary>
        /// 重写集合类型的Add方法
        /// </summary>
        /// <param name="item"></param>
        public new void Add(ChildType item)
        {
            base.Add(item);
        }
        /// <summary>
        /// 新建对象
        /// </summary>
        /// <returns></returns>
        public abstract ChildType New();
        /// <summary>
        /// 获取子对象的类型
        /// </summary>
        /// <returns></returns>
        public Type GetChildType()
        {
            return typeof(ChildType);
        }
    }
}
